﻿package cn.com.truelore.adapter;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.com.truelore.R;
import cn.com.truelore.common.Constants;
import cn.com.truelore.vo.PriceVO;

import android.content.Context;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TabContentPriceAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	/**
	 * 需要显示的数据列表
	 */
	private List<PriceVO> dataList;

	private String strDollar = "";

	public TabContentPriceAdapter(Context context) {
		mInflater = LayoutInflater.from(context);
		strDollar = context.getResources().getString(R.string.dollar);
	}

	public int getCount() {
		return dataList.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		PriceListViewHolder holder = new PriceListViewHolder();
		PriceVO priceVO = dataList.get(position);
		if (Constants.TYPE_HEDER == priceVO.getType()) {
			/*convertView = mInflater.inflate(R.layout.listview_item_price_title,
					null);
			holder.textViewElevator = (TextView) convertView
					.findViewById(R.id.textViewElevator);
			holder.textViewElevator.setText(R.string.listviewtitle1);
			holder.textViewFuture = (TextView) convertView
					.findViewById(R.id.textViewFutures);
			holder.textViewFuture.setText(R.string.listviewtitle2);
			holder.textViewBasis = (TextView) convertView
					.findViewById(R.id.textViewBasis);
			holder.textViewBasis.setText(R.string.listviewtitle3);
			holder.textViewCash = (TextView) convertView
					.findViewById(R.id.textViewCash);
			holder.textViewCash.setText(R.string.listviewtitle4);
			holder.imgViewStatus = (ImageView) convertView
					.findViewById(R.id.imgViewPriceItemStatus);
			convertView.setTag(holder);
			ImageView texView = (ImageView) convertView
					.findViewById(R.id.imgViewPriceTitleStatus);
			texView.setVisibility(8);*/

		} else {
			if (Constants.TYPE_CMD_TITLE == priceVO.getType()) {
				convertView = mInflater.inflate(
						R.layout.listview_item_price_title2, null);
				holder.textViewElevator = (TextView) convertView
						.findViewById(R.id.textViewListViewTitle);
				holder.textViewElevator.setText(priceVO.getENm());
				TextPaint tp = holder.textViewElevator.getPaint();
				tp.setFakeBoldText(true);
			} else {
				if (position % 2 == 0) {
					convertView = mInflater.inflate(
							R.layout.listview_item2_price, null);
				} else {
					convertView = mInflater.inflate(
							R.layout.listview_item1_price, null);
				}
				holder.textViewElevator = (TextView) convertView
						.findViewById(R.id.textViewElevator);
				holder.textViewFuture = (TextView) convertView
						.findViewById(R.id.textViewFutures);
				holder.textViewBasis = (TextView) convertView
						.findViewById(R.id.textViewBasis);
				holder.textViewCash = (TextView) convertView
						.findViewById(R.id.textViewCash);
				holder.imgViewStatus = (ImageView) convertView
						.findViewById(R.id.imgViewPriceTitleStatus);

				convertView.setTag(holder);

				holder.textViewElevator.setText(priceVO.getENm());
				if (Constants.TYPE_CHICAGO == priceVO.getType()
						|| Constants.TYPE_MIN == priceVO.getType()) {
					holder.textViewFuture.setText(priceVO.getF());
					TextPaint tp = holder.textViewElevator.getPaint();
					tp.setFakeBoldText(true);
				} else {
					if (StringUtils.isBlank(priceVO.getC()) == false
							&& Constants.CHAR_H.equals(priceVO.getC()) == false) {
						holder.textViewCash.setText(strDollar + priceVO.getC());
					} else {
						holder.textViewCash.setText(priceVO.getC());
					}
					holder.textViewFuture.setText(priceVO.getF());
					holder.textViewBasis.setText(priceVO.getB());
					holder.imgViewStatus.setVisibility(8);
				}

			}
		}
		return convertView;
	}

	public List<PriceVO> getDataList() {
		return dataList;
	}

	public void setDataList(List<PriceVO> dataList) {
		this.dataList = dataList;
	}

	public final class PriceListViewHolder {
		public TextView textViewElevator;
		public TextView textViewFuture;
		public TextView textViewBasis;
		public TextView textViewCash;
		public ImageView imgViewStatus;
	}
}
